package com.xc.h05.controller.renMengBinController;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Usermark;
import com.xc.h05.service.renMengBinService.UsermarkService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/usermark")
public class UsermarkController {
    @Autowired
    private UsermarkService usermarkService;
    //增加
    @PostMapping()//wc修改"/add"
    public R add(@RequestBody Usermark usermark) {
        int i = usermarkService.add(usermark);
        if (i > 0) {
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }
    //删除
    @DeleteMapping("/{id}")
    public R remove(@PathVariable("id") Long id) {
        int i = usermarkService.remove(id);
        if (i > 0) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    //修改
    @PutMapping()
    public R update(@RequestBody Usermark usermark) {
        int i = usermarkService.update(usermark);
        if (i > 0) {
            return R.ok("修改成功");
        }
        return R.fail("修改失败");
    }
    //批量删除
    @DeleteMapping("/deleteByIds")
    public R deleteByIds(@RequestBody java.util.List<Long> ids) {
        int i = usermarkService.removeByIds(ids);
        if (i > 0) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    //分页查询
    @GetMapping("/getAll")
    public R getAll(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
            Usermark usermark
    ){
        PageInfo<Usermark> pageInfo = usermarkService.selectAll(pageNum, pageSize, usermark);
        if (pageInfo != null){
            return R.ok(pageInfo);
        }else {
            return R.fail("查询失败");
        }
    }
}
